package math.vectorSpace.R3.object;

import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.CubicCurve2D;

import math.vectorSpace.R2.Point2D;
import math.vectorSpace.R3.Point3D;
import math.vectorSpace.R3.Vector3D;
import math.vectorSpace.R3.visualization.Visualizable;

public abstract class Object3D implements Visualizable{

    protected Point3D center;

    protected Vector3D[] v;

    protected int totalPts;

    protected double distance;
    
    public void scale(double scaleFactor) {
        for (int i = 0; i < totalPts; i++) {
            v[i] = v[i].scale(scaleFactor);
        }
    }

    public Point3D getCenter() {
        return center;
    }

    public void setCenter(Point3D center) {
        this.center = center;
    }

    public void move(double x, double y, double z) {
        center.add(x, y, z);
    }

    /** 
     * @param angle the counterclockwise rotation angle around the x axis
     */
    public void rotateX(double angle) {
        for (int i = 0; i < v.length; i++) {
            v[i].set(v[i].rotateX(angle));
        }
    }

    /**
     * 
     * @param angle the counterclockwise rotation angle around the y axis
     */
    public void rotateY(double angle) {
        for (int i = 0; i < v.length; i++) {
            v[i].set(v[i].rotateY(angle));
        }
    }

    /**
     * 
     * @param angle the counterclockwise rotation angle around the z axis
     */
    public void rotateZ(double angle) {
        for (int i = 0; i < v.length; i++) {
            v[i].set(v[i].rotateZ(angle));
        }
    }

    protected static void addPoint(Polygon polygon, Point2D point) {
        polygon.addPoint((int) point.getX(), (int) point.getY());
    }

    protected static void drawCubicCurve(Point2D pt1, 
            Point2D ctrlPt1, Point2D ctrlPt2, Point2D pt2, Graphics2D g) {
        g.draw(new CubicCurve2D.Double(pt1.getX(), pt1.getY(), ctrlPt1.getX(), ctrlPt1.getY(), ctrlPt2.getX(), ctrlPt2.getY(), pt2.getX(), pt2.getY()));
    }

    protected static void drawSegment(Point2D pt1, Point2D pt2, Graphics2D g) {
        g.drawLine((int) pt1.getX(), (int) pt1.getY(), (int) pt2.getX(), (int) pt2.getY());
    }
}
